package com.farm.learn.service.impl;

import com.farm.learn.domain.Usermajor;
import com.farm.core.time.TimeTool;
import org.apache.log4j.Logger;
import com.farm.learn.dao.UsermajorDaoInter;
import com.farm.learn.service.UsermajorServiceInter;
import com.farm.core.sql.query.DBRule;
import com.farm.core.sql.query.DBRuleList;
import com.farm.core.sql.query.DataQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import com.farm.core.auth.domain.LoginUser;

/* *
 *功能：用户专业服务层实现类
 *详细：
 *
 *版本：v0.1
 *作者：FarmCode代码工程
 *日期：20150707114057
 *说明：
 */
@Service
public class UsermajorServiceImpl implements UsermajorServiceInter {
	@Resource
	private UsermajorDaoInter usermajorDaoImpl;

	private static final Logger log = Logger.getLogger(UsermajorServiceImpl.class);

	@Override
	@Transactional
	public Usermajor insertUsermajorEntity(Usermajor entity) {
		// TODO 自动生成代码,修改后请去除本注释
		// entity.setCuser(user.getId());
		// entity.setCtime(TimeTool.getTimeDate14());
		// entity.setCusername(user.getName());
		// entity.setEuser(user.getId());
		// entity.setEusername(user.getName());
		// entity.setEtime(TimeTool.getTimeDate14());
		// entity.setPstate("1");
		return usermajorDaoImpl.insertEntity(entity);
	}

	@Override
	@Transactional
	public Usermajor editUsermajorEntity(Usermajor entity, LoginUser user) {
		// TODO 自动生成代码,修改后请去除本注释
		Usermajor entity2 = usermajorDaoImpl.getEntity(entity.getId());
		// entity2.setEuser(user.getId());
		// entity2.setEusername(user.getName());
		// entity2.setEtime(TimeTool.getTimeDate14());
		entity2.setUserid(entity.getUserid());
		entity2.setPstate(entity.getPstate());
		entity2.setMajorid(entity.getMajorid());
		entity2.setEtime(entity.getEtime());
		entity2.setLtime(entity.getLtime());
		entity2.setStime(entity.getStime());
		entity2.setNnum(entity.getNnum());
		entity2.setAnum(entity.getAnum());
		entity2.setSnum(entity.getSnum());
		entity2.setCnum(entity.getCnum());
		entity2.setProcess(entity.getProcess());
		entity2.setUsetime(entity.getUsetime());
		entity2.setId(entity.getId());
		usermajorDaoImpl.editEntity(entity2);
		return entity2;
	}

	@Override
	@Transactional
	public void deleteUsermajorEntity(String id, LoginUser user) {
		// TODO 自动生成代码,修改后请去除本注释
		usermajorDaoImpl.deleteEntity(usermajorDaoImpl.getEntity(id));
	}

	@Override
	@Transactional
	public Usermajor getUsermajorEntity(String id) {
		// TODO 自动生成代码,修改后请去除本注释
		if (id == null) {
			return null;
		}
		return usermajorDaoImpl.getEntity(id);
	}

	@Override
	@Transactional
	public DataQuery createUsermajorSimpleQuery(DataQuery query) {
		DataQuery dbQuery = DataQuery.init(query,
				"WLP_U_USERMAJOR a left join ALONE_AUTH_USER b on a.userid=b.id left join ALONE_AUTH_USERORG c on c.userid=b.id left join ALONE_AUTH_ORGANIZATION d on c.ORGANIZATIONID=d.id left join WLP_L_MAJOR e on e.id=a.majorid",
				"b.name as USERNAME,e.TITLE as MAJORTITLE,b.loginname as LOGINNAME,d.NAME AS ORGNAME,a.ID as ID,a.USERID as USERID,a.PSTATE as PSTATE,a.MAJORID as MAJORID,a.ETIME as ETIME,a.LTIME as LTIME,a.STIME as STIME,a.NNUM as NNUM,a.ANUM as ANUM,a.SNUM as SNUM,a.CNUM as CNUM,a.PROCESS as PROCESS,a.USETIME as USETIME");
		return dbQuery;
	}

	@Override
	@Transactional
	public void deleteUsermajor(String userid, String majorid) {
		usermajorDaoImpl.deleteEntitys(DBRuleList.getInstance().add(new DBRule("USERID", userid, "="))
				.add(new DBRule("MAJORID", majorid, "=")).toList());
	}

}
